/**
 * Encryption keys manager
 *
 */

#ifndef	INCOGNITO_KEYMNGR_H
#define	INCOGNITO_KEYMNGR_H

#include "dh.h"

#include <chord_types.h>
#include <chord.h>

#include <map>

class incognito_impl;

// Result of encryption key lookup
enum getkeyres {
	INCOGNITO_KEY_OK	= 0,
	INCOGNITO_KEY_FAILED	= 1,
};

// Callback typedefs
typedef callback<void,bigint,getkeyres>::ptr cbgetkey;

class keymngr:public virtual refcount {
		typedef std::map<chordID,dh> keymap;
	public:
		// Get encryption key for node n and call cb
		void get_key(incognito_impl *ic, chord_node &n, cbgetkey cb);
		// Get encryption key for node n and call cb (don't establish new if key doesn't exists yet)
		void get_key(incognito_impl *ic, chordID id, cbgetkey cb);

		// Callback for incognito_impl::dh_exchange (called from get_key)
		void get_key_dh_exchange_cb(chord_node n, cbgetkey cb, bigint remote_pubkey);
		
		// Called when remote node wants to agree secret
		bigint on_key_exchange(chordID node,bigint p, bigint g, bigint remote_pubkey);

		// Print statistics about keys
		void print_stats();
	private:
		keymap _keys;
	
};

#endif	/* INCOGNITO_KEYMNGR_H*/
